'''
Case Type： 故障&可靠性测试
Case Name： 工具log丢失 gs_ctl
Create At: 2020/07/20
@zou_jialiang0505328114
Descption:
1、删除工具日志
2.重启数据库
3.查看数据库状态
'''
import os
import unittest
import _thread
import time
from yat.test import macro
from yat.test import Node
from testcase.utils.CommonSH import *
from testcase.utils.Common import Common
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class Deletaduit(unittest.TestCase):
    commonshpri = CommonSH('PrimaryDbUser')
    nodes_tuple = ('PrimaryDbUser', 'Standby1DbUser', 'Standby2DbUser')

    @RestartDbCluster(*nodes_tuple)
    def setUp(self):
        self.log = Logger()
        self.log.info('------------Opengauss_Reliability_Dbsys_Case202.py start------------')
        self.rootNode = Node()
        self.dbUserNode1 = Node(node='PrimaryDbUser')
        self.dbUserNode = Node(node='PrimaryRoot')
        self.dbUserNode2 = Node(node='Standby1Root')
        self.dbUserNode3 = Node(node='Standby1DbUser')
        self.ctl_log_path = macro.PG_LOG_PATH.rsplit('/', 1)[0] + '/bin/gs_ctl'

    def test_startdb(self):
        self.log.info("------------------------------删除gs_ctl log-------------------")
        mv_cmd = 'rm -rf ' + self.ctl_log_path + '/* '
        self.log.info(mv_cmd)
        result = self.dbUserNode1.sh(mv_cmd).result()
        self.log.info(result)

        self.log.info("-----------------------重启数据库------------------")
        stop_result = self.commonshpri.stopDbCluster()
        self.assertTrue(stop_result)
        start_result = self.commonshpri.startDbCluster()
        self.assertTrue(start_result)

        self.log.info("------------------查询数据库状态------------------")
        status = self.commonshpri.getDbClusterStatus("status")
        self.assertTrue(status)

    def tearDown(self):
        self.log.info(
            '-------------------------------reliability_dbsys202.py finish------------------------------------')
